import { reqUserLogin } from '@/api/user'
export default {
  // 模块里的state 需要用一个函数返回
  namespaced: true,
  state: () => {
    return {
      profile: {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  mutations: {
    SET_PROFILE (state, payload) {
      state.profile = payload
    },
    // 清空state数据
    CLEAR_PROFILE (state) {
      state.profile = {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  actions: {
    async login (ctx, payload) {
      const res = await reqUserLogin(payload)
      ctx.commit('SET_PROFILE', res.result)
    }
  }
}
